<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电灯泡</title>
</head>
<body>
    <div class="bulb">
        <img src="../img/pic_bulboff.gif" alt="灯泡" id="pic">
        <button id="switch">开</button>
    </div>
</body>

<script>
    var oImg = document.getElementById("pic");
    var oSwitch = document.getElementById("switch");
    var flag = false;

    oSwitch.addEventListener('click',function(){
        if(!flag){
            oImg.src = '../img/pic_bulbon.gif';
            flag = true;
            this.innerText = '关';
        }else{
            oImg.src = '../img/pic_bulboff.gif';
            flag = false;
            this.innerText = '开';
        }
    },false);
</script>
</html>